package main.controller;

import main.GlobalConfig;
import main.RequestHelper;
import main.TimeHelper;
import main.database.AccountHelper;
import main.database.NotifyHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.ModelMap;

@Controller
public class HelpPageController {
    @RequestMapping(value = "/help")
    public String helpPage(HttpServletRequest request, ModelMap modelMap) {
        String uuid = RequestHelper.getUserUUIDFromRequest(request);
        String account = AccountHelper.getAccountInfoFromUUID(uuid);
        boolean isLogin = true;
        if (account == null || account.isEmpty()) {
            isLogin = false;
        }
        boolean isAdmin = AccountHelper.isAdminFromUUID(uuid);

        long unread = 0;
        if (isLogin) {
            unread = NotifyHelper.countUnreadNotify(uuid);
            modelMap.put("unread", unread);
        }

        modelMap.put("siteName", GlobalConfig.siteName);
        modelMap.put("isLogin", isLogin);
        modelMap.put("isAdmin", isAdmin);
        modelMap.put("year2year", TimeHelper.getFormattedYear2Year());

        return "help";
    }
}